# Maintainer: Andreas Radke <andyrtr@archlinux.org>

pkgname=foomatic-db-engine
arch=('x86_64')
pkgver=20220521
pkgrel=1
epoch=4
url="http://www.linuxprinting.org/foomatic.html"
pkgdesc="Foomatic - Foomatic's database engine generates PPD files from the data in Foomatic's XML database. It also contains scripts to directly generate print queues and handle jobs."
license=('GPL2')
depends=('perl' 'libxml2' "cups-filters>=1.0.42" 'bash' 'perl-xml-libxml' 'perl-clone' 'perl-dbi')
makedepends=('cups' 'ghostscript' 'a2ps' 'wget' 'perl-xml-libxml' 'foomatic-db' 'git')
optdepends=('foomatic-db:	linuxprinting.org xml files database to create ppd driver files')
backup=('etc/foomatic/defaultspooler')

# check https://github.com/OpenPrinting/foomatic-db-engine

#source=(foomatic-db-engine::git+https://github.com/OpenPrinting/foomatic-db-engine#commit=068c92311018a75c621c57328845b439d789bf50	#20200131  # master development branch
source=(foomatic-db-engine::git+https://github.com/OpenPrinting/foomatic-db-engine-4#commit=bd265b77a9f66f672bf1e3f0803145f2eccabf06	#20200131  # master stable branch
)
sha256sums=('SKIP')

pkgver() {
  date +%Y%m%d
}

build() {
  export LIB_CUPS="/usr/lib/cups"
  cd "$pkgname" #-$pkgver
  ./make_configure
  PERL_INSTALLDIRS=vendor \
  ./configure --prefix=/usr \
    --sbindir=/usr/bin
  make
}

package() {
  cd "$pkgname" #-$pkgver
  make DESTDIR="${pkgdir}" install

  # preset default spooler
  echo cups > "${pkgdir}"/etc/foomatic/defaultspooler
  # add some docs
  install -Dm644 USAGE "${pkgdir}"/usr/share/doc/${pkgname}/USAGE
  install -Dm644 README "${pkgdir}"/usr/share/doc/${pkgname}/README

  # cleanup
  rm -r "${pkgdir}"/usr/lib/perl5
}
